package com.fengxu.nio.zerocopy;

import java.io.DataInputStream;
import java.net.ServerSocket;
import java.net.Socket;

// 使用老版本的IO服务器进行数据拷贝
public class OldIOServer {

    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(6666);
        System.out.println("服务器开始监听6666端口...");
        Socket client = serverSocket.accept();
         DataInputStream dis = new DataInputStream(client.getInputStream());
         byte[] bytes = new byte[4096];
         int fileSize = 0;
         while (true){
             int len = dis.read(bytes,0,bytes.length);
             if(len == -1){
                 System.out.println("数据读取完毕,字节数:"+fileSize);
                 break;
             } else {
                 fileSize += len;
             }
         }

         dis.close();
         client.close();
         serverSocket.close();
    }
}
